package com.ipzoe.common.repository;

import com.ipzoe.common.bean.entity.RoleAdminMenu;
import com.ipzoe.common.util.DefaultMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 角色菜单关联Repository
 * <p>
 * Created 2018/01/19.
 *
 * @author pfzhang
 */
@Mapper
public interface RoleAdminMenuRepository extends DefaultMapper<RoleAdminMenu> {

    /**
     * 根据角色ID删除角色菜单绑定对象
     *
     * @param roleId 角色ID
     */
    @Delete("delete from role_admin_menu where role_id = #{0} and del_flag = 0")
    void deletedByRoleId(Long roleId);

    /**
     * 根据角色ID和菜单ID获取角色菜单绑定对象
     *
     * @param roleId 角色ID
     * @param menuId 菜单ID
     * @return 角色菜单绑定对象
     */
    @Select("select * from role_admin_menu where del_flag = 0 and role_id = #{0} and admin_menu_id = #{1}")
    RoleAdminMenu selectByRoleIdAndMenuId(Long roleId, Long menuId);

    /**
     * 根据角色ID获取角色绑定菜单ID集合
     *
     * @param roleId 角色ID
     * @return 菜单ID集合
     */
    @Select("select admin_menu_id from role_admin_menu where del_flag = 0 and role_id = #{0}")
    List<Long> getIdListByRoleId(Long roleId);
}
